<#include "../common/header.htm">
<div class="content-wrapper">
	<section class="content-header">
		<ol class="breadcrumb">
			<li><a href="${ctx}/">首页</a></li>
			<li class="active"><a href="${ctx}/gateway/list">网关管理</a></li>
		</ol>
	</section>
	<section class="content">
		<form action="${ctx}/gateway/list" method="get" id="listForm">
			<div class="box">
				<div class="box-header">
					<div class="row">
						<div class="col-sm-9">
							<div class="col-sm-2">
								<input type="text" class="form-control" name="name" value="${name!}" placeholder="请输入网关名称" />
							</div>
							<div class="col-sm-2">
								<input type="text" class="form-control" name="gwName" value="${gwName!}" placeholder="请输入网关标识" />
							</div>
						    <div class="col-sm-2">
								<label style="float: left;">状态：</label> 
								<select class="form-control" name="gwState" style="width: 100px; float: left;">
								   <option value="">全部</option>
								   <#list stateMap as key, value>
										<#if gwState?exists && key == gwState?string>
											<option value="${key}" selected="selected">${value}</option>
										<#else>
											<option value="${key}">${value}</option>
										</#if> 
								   </#list>
								 </select>
							</div>
							<div class="col-sm-1">
								<input type="button"  class="btn btn-default btn-search" onclick="gateways.query();" value="查询" />
							</div>
						</div>
						<div class="col-sm-3">
							<input type="button"  class="btn btn-primary" onclick="gateways.form();" value="新增" />
						</div>
					</div>
				</div>
				<div class="box-body">
					<table class="table table-hover table-bordered table-striped table-hide">
						<thead>
							<tr>
								<th style="width:60px;">#</th>
								<th style="width:100px;">网关ID</th>
								<th>网关名称</th>
								<th>网关标识</th>
								<th>并发数</th>
								<th>授权数</th>
								<th>录音地址</th>
								<th>网关状态</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody>
							<#list page.content as u>
							<tr>
								<td>${page.size * page.number+u_index+1}</td>
								<td>${u.gatewayId!}</td>
								<td>${u.name!}</td>
								<td>${u.gwName!}</td>
								<#if concurrentNumMap?? && u.gwName?? && concurrentNumMap["${u.gwName}"]?? >
									<td>${concurrentNumMap["${u.gwName}"]!}</td>
								<#else>
									<td></td>
								</#if>
								<td>${u.authorizedNum!}</td>
								<td title="${u.voxServerAddr!}">${u.voxServerAddr!}</td>
								<#if u.state?? && stateMap["${u.state}"]?? >
									<td>${stateMap["${u.state}"]!}</td>
								<#else>
									<td></td>
								</#if>
								<td>
									<#if u.state == 1>
										<a href="${ctx}/gateway/changeState?gatewayId=${u.gatewayId}&state=2">停用</a>
									<#else>
										<a href="${ctx}/gateway/changeState?gatewayId=${u.gatewayId}&state=1">启用</a>
									</#if>
									<a href="javascript:void(0)" onclick="gateways.form('${u.gatewayId}')">编辑</a>
									<#-- <a href="${ctx}/gateway/deleteOne?gatewayId=${u.gatewayId}">删除</a> -->
									<a href="javascript:void(0)" onclick="gateways.deleteWg('${u.gatewayId}')">删除</a>
								</td>
							</tr>
							</#list>
						</tbody>
					</table>
					<#include "../common/page.htm">
				</div>
			</div>
		</form>
	</section>
</div>

<script type="text/javascript">
	var is_submit=false;
	var gateways = {
		query: function () {
			$(":input[name='pageNumber']").val(0);
			$("form").submit();
		},
		/**
		 * 新增或修改网关
		 * @param id 主键 
		 */
		form : function (id) {
			if(is_submit){
				return;
			}
			is_submit=true;
			id = id ? id : "";
			var title = id ? "修改网关" : "新增网关";
			var j = 0;
			base.getView({
				url:"${ctx}/gateway/form?gatewayId="+id,
				success:function(result){
					bootbox.dialog({
						title:title,
						message:result,
						size:"large",
						closeButton : false,
						buttons:{
							cancel:{
								label:"取消",
								className:"btn btn-secondary",
								callback:function(){
									is_submit=false;
								}
							},
							sure:{
								label:"确定",
								className:"btn btn-primary",
								callback:function(){
									if (j != 0) {
										is_submit=false;
										return ;
									}
									j++;
									base.validAndAjaxSubmitJson($("#addGateway"), function () {
										j = 0;
									}, function (data) {
										// console.log(data.result);
										if (data.result == 'success') {
											$("#listForm").submit();
										} else {
											j = 0;
										}
									});
									return false;
								}
							}
						}
					})
				}
			})
		},
		/* 删除网关 */
		deleteWg : function (id) {
			if(is_submit){
				return;
			}
			is_submit = true;
			var title = '删除网关';
			var j = 0;
			base.getView({
				url:"${ctx}/gateway/deleteWg?gatewayId="+id,
				success:function(result){
					bootbox.dialog({
						title:title,
						message:result,
						size:"small",
						closeButton : false,
						buttons:{
							cancel:{
								label:"取消",
								className:"btn btn-secondary",
								callback:function(){
									is_submit=false;
								}
							},
							sure:{
								label:"确定",
								className:"btn btn-primary",
								callback:function() {
									if (j != 0) {
										is_submit=false;
										return ;
									}
									j++;
									base.validAndAjaxSubmit($("#deleteWg"), $("#listForm"), function () {
										j = 0;
									});
									return false;
								}
							}
						}
					})
				}
			});
		}
	}
</script>
<#include "../common/footer.htm">